/*
 * BncsAuthInfoClient.h
 *
 *  Created on: Nov 20, 2008
 *      Author: nathan
 */

#ifndef BNCSAUTHINFOCLIENT_H_
#define BNCSAUTHINFOCLIENT_H_

#include "BncsMessage.h"
#include "BncsMessageFactory.h"

class BncsAuthInfoClientData : public QSharedData
{
public:
	quint32 protocolId;
	quint32 platformId;
	quint32 productId;
	quint32 version;
	quint32 language;
	quint32 localIP;
	quint32 tzbias;
	quint32 localeId;
	quint32 langId;
	QByteArray countryAbbr;
	QByteArray countryFull;
};

class BncsAuthInfoClient : public BncsMessage
{
	BNCS_MESSAGE_REGISTER(BncsAuthInfoClient, 0x50);

public:
	QSharedDataPointer<BncsAuthInfoClientData> d;

public:
	quint32 id()
	{
		return id;
	}

	int size()
	{
		return sizeof(d->protocolId) + sizeof(d->platformId) + sizeof(d->productId) +
		       sizeof(d->version) + sizeof(d->language) + sizeof(d->localIP) +
		       sizeof(d->tzbias) + sizeof(d->localeId) + sizeof(d->langId) +
		       (d->countryAbbr.size() + 1) + (d->countryFull.size() + 1);
	}

	void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> d->protocolId;
		ds >> d->platformId;
		ds >> d->productId;
		ds >> d->version;
		ds >> d->language;
		ds >> d->localIP;
		ds >> d->tzbias;
		ds >> d->localeId;
		ds >> d->langId;
		d->countryAbbr = readStringFrom(ds);
		d->countryFull = readStringFrom(ds);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> d->protocolId;
		ds >> d->platformId;
		ds >> d->productId;
		ds >> d->version;
		ds >> d->language;
		ds >> d->localIP;
		ds >> d->tzbias;
		ds >> d->localeId;
		ds >> d->langId;
		d->countryAbbr = readStringFrom(ds);
		d->countryFull = readStringFrom(ds);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

#endif /* BNCSAUTHINFOCLIENT_H_ */
